package com.jaay.common;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.ThreadLocalRandom;

@Component
public class RandomUtils {

    /**
     * 订单编号前缀
     */
    private static final String ORDER_PREFIX = "E";
    private static final String DATE_FORMAT = "YYYYMMddHHmm";


    /**
     * 生成订单号
     *
     * @return 返回订单号
     */
    public String generateOrderNo() {

        StringBuilder builder = new StringBuilder();
        builder.append(ORDER_PREFIX);
        builder.append(new SimpleDateFormat(DATE_FORMAT).format(Calendar.getInstance().getTime()));
        builder.append(ThreadLocalRandom.current().nextInt(1000, 9999));
        return builder.toString();
    }

    /**
     * 生成商户编号
     *
     * @return 商户编号
     */
    public String generateMerchantNo() {

        StringBuilder builder = new StringBuilder();
        builder.append(new SimpleDateFormat(DATE_FORMAT).format(Calendar.getInstance().getTime()));
        builder.append(ThreadLocalRandom.current().nextInt(10000, 99990));
        return builder.toString();
    }


}
